package com.bw.mvvm_common.network;

import com.bw.mvvm_common.network.inteceptor.ErroInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

/**
 * 封装接口请求的公共OkhttpClient
 * 3个超时时间
 * 日志拦截器->loggerinterceptor
 * */
public abstract class BaseImpl implements HttpInterface{

    protected OkHttpClient.Builder createOkHttpBuilder(){
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(interceptor);//添加日志拦截器
        builder.addInterceptor(new ErroInterceptor());
        //超时设置
        builder.connectTimeout(30, TimeUnit.SECONDS);
        builder.writeTimeout(30,TimeUnit.SECONDS);
        builder.readTimeout(30,TimeUnit.SECONDS);
        return builder;
    }

}
